package com.hbsx.why.adapter;

import android.content.Context;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.PagerAdapter;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.hbsx.why.R;
import com.hbsx.why.model.bean.UserBean;
import com.hbsx.why.utils.LogUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by hugeterry(http://hugeterry.cn)
 * Date: 16/1/28 17:24
 */
public class MyActivityPagerAdapter extends PagerAdapter {
    private List<Fragment> mFragments = new ArrayList<>();
    private List<UserBean> userBeanList;
    private ArrayList<View> viewList;
    private LayoutInflater LayoutInflater;
    private Context context;


    public MyActivityPagerAdapter(List<Fragment> mFragments, List<UserBean> userBeanList, Context context) {
        this.mFragments = mFragments;
        this.userBeanList = userBeanList;
        this.context = context;
        LayoutInflater = android.view.LayoutInflater.from(context);
        viewList = new ArrayList<View>();
        for (int i = 0;i<userBeanList.size();i++){
            viewList.add(LayoutInflater.inflate(R.layout.activity_main_new,null));

        }
    }


    @Override
    public int getCount() {
        return viewList.size();
    }

    @Override
    public boolean isViewFromObject(View view, Object object) {
        return view == object;
    }

    @Override
    public CharSequence getPageTitle(int position) {
        return userBeanList.get(position).getName();
    }

    @Override
    public Object instantiateItem(ViewGroup container, int position) {
        container.addView(viewList.get(position));
        return viewList.get(position);
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        container.removeView(viewList.get(position));
    }
}
